package cn.kongwg.demo1;

/**
 * @author kongwg
 * @create 2021-05-17 22:01
 */
public class TreeTest {
    public static class Node {
        private int value;
        private Node left;
        private Node right;

        public Node(int value) {
            this.value = value;
        }
    }

    public static void preSort(Node root) {
        System.out.println(root.value);
        if (root.left != null) {
            preSort(root.left);
        }
        if (root.right != null) {
            preSort(root.right);
        }
    }

    public static void midSort(Node root) {
        if (root.left != null) {
            midSort(root.left);
        }
        System.out.println(root.value);
        if (root.right != null) {
            midSort(root.right);
        }
    }

    public static void nextSort(Node root) {
        if (root.left != null) {
            nextSort(root.left);
        }
        if (root.right != null) {
            nextSort(root.right);
        }
        System.out.println(root.value);
    }

    public static void main(String[] args) {
        Node root = new Node(1);
        root.left = new Node(2);
        root.right = new Node(3);
        root.left.left = new Node(4);
        root.left.right = new Node(5);
        root.right.left = new Node(6);
        root.right.right = new Node(7);

        System.out.println("___________________");
        preSort(root);
        System.out.println("___________________");
        midSort(root);
        System.out.println("___________________");
        nextSort(root);
    }





}
